package com.example.a66666.yuejian.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a66666.yuejian.Activity.ActivityDetailActivity;
import com.example.a66666.yuejian.Bean.ActivityBean;
import com.example.a66666.yuejian.MyViewHolder.ItemViewHolder;
import com.example.a66666.yuejian.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by 66666 on 2018/9/28.
 */

public class ActivityAdapter extends RecyclerView.Adapter{

     private List<ActivityBean> activityBeanList;

     public void setData(List<ActivityBean> list){
         activityBeanList=list;
         notifyDataSetChanged();
     }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.recyclerview_item,parent,false);
        ItemViewHolder viewHolder=new ItemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
          final ItemViewHolder viewHolder=(ItemViewHolder)holder;
          final ActivityBean activityBean=activityBeanList.get(position);
          String name=activityBean.getAcname();
          String time=activityBean.getAtime();
          String place=activityBean.getPlace();
          String pic=activityBean.getApic();
          viewHolder.name.setText("活动名称："+name);
          viewHolder.time.setText("活动时间："+time);
          viewHolder.place.setText("活动地点："+place);
          Picasso.with(viewHolder.imageView.getContext()).load("http://10.0.2.2/yuejian/public/static/activitypic/"+pic).into(viewHolder.imageView);

         viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 int pos=viewHolder.getLayoutPosition();
                 Intent intent=new Intent(v.getContext(), ActivityDetailActivity.class);
                 intent.putExtra("activityID",activityBeanList.get(pos).getAcid());
                 v.getContext().startActivity(intent);
             }
         });

    }

    @Override
    public int getItemCount() {
        if(activityBeanList!=null)
            return activityBeanList.size();
        else
            return 0;
    }
}
